#include "DynamicSkybox.h"
#include <SERender/Resourses/Loader/VertexArrayLoader.h>

namespace SEngine
{   
    DynamicSkybox::DynamicSkybox()
        : Drawable()
    {
        VertexArrayLoader<3> loader(std::make_unique<CurrentDrive>());
        // positions          
        loader.PushVertex({-1.0f,  1.0f, -1.0f});
        loader.PushVertex({-1.0f, -1.0f, -1.0f});
        loader.PushVertex({1.0f, -1.0f, -1.0f});
        loader.PushVertex({1.0f, -1.0f, -1.0f});
        loader.PushVertex({1.0f,  1.0f, -1.0f});
        loader.PushVertex({-1.0f,  1.0f, -1.0f});

        loader.PushVertex({-1.0f, -1.0f,  1.0f});
        loader.PushVertex({-1.0f, -1.0f, -1.0f});
        loader.PushVertex({-1.0f,  1.0f, -1.0f});
        loader.PushVertex({-1.0f,  1.0f, -1.0f});
        loader.PushVertex({-1.0f,  1.0f,  1.0f});
        loader.PushVertex({-1.0f, -1.0f,  1.0f});

        loader.PushVertex({1.0f, -1.0f, -1.0f});
        loader.PushVertex({1.0f, -1.0f,  1.0f});
        loader.PushVertex({1.0f,  1.0f,  1.0f});
        loader.PushVertex({1.0f,  1.0f,  1.0f});
        loader.PushVertex({1.0f,  1.0f, -1.0f});
        loader.PushVertex({1.0f, -1.0f, -1.0f});

        loader.PushVertex({-1.0f, -1.0f,  1.0f});
        loader.PushVertex({-1.0f,  1.0f,  1.0f});
        loader.PushVertex({1.0f,  1.0f,  1.0f});
        loader.PushVertex({1.0f,  1.0f,  1.0f});
        loader.PushVertex({1.0f, -1.0f,  1.0f});
        loader.PushVertex({-1.0f, -1.0f,  1.0f});

        loader.PushVertex({-1.0f,  1.0f, -1.0f});
        loader.PushVertex({1.0f,  1.0f, -1.0f});
        loader.PushVertex({1.0f,  1.0f,  1.0f});
        loader.PushVertex({1.0f,  1.0f,  1.0f});
        loader.PushVertex({-1.0f,  1.0f,  1.0f});
        loader.PushVertex({-1.0f,  1.0f, -1.0f});

        loader.PushVertex({-1.0f, -1.0f, -1.0f});
        loader.PushVertex({-1.0f, -1.0f,  1.0f});
        loader.PushVertex({1.0f, -1.0f, -1.0f});
        loader.PushVertex({1.0f, -1.0f, -1.0f});
        loader.PushVertex({-1.0f, -1.0f,  1.0f});
        loader.PushVertex({1.0f, -1.0f,  1.0f});

        this->SetMesh(std::make_unique<Mesh>(loader.CreateVertexArray()));
        this->SetAPIType(DrawAPIType::DrawArrays);
        this->SetMode(ElemMode::TRIANGLES);
    }

    void DynamicSkybox::SetMaterial(ResRef<Material> material)
    {
        material.Value().GetPSO().blend = false;
        material.Value().GetPSO().cullFace = true;
        material.Value().GetPSO().cullFront = false;
        material.Value().GetPSO().depth = false;
        Drawable::SetMaterial(material); 
    }

    void DynamicSkybox::Draw(Renderer &renderer)
    {
        Drawable::Draw(renderer);
    }
}